<include file="./VMSTpl/Admin/header.html" />
<div class="alert alert-info alert-dismissable" style="margin-top:-20px;{$styles['tips'][0]}">
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  <strong>注意!</strong>&nbsp;&nbsp;&nbsp;&nbsp;请在右上方的输入框输入需要修改信息对应的飞机号或者出厂号 </div>
<div class="alert alert-warning alert-dismissable" style="margin-top:-20px;{$styles['tips'][1]}">
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  <strong>注意!</strong>&nbsp;&nbsp;&nbsp;&nbsp;{$tips}</div>
<div class="container">
  <h2>{$title}</h2>
  <!--
  <div class="col-md-12"> <a id="unit" type="button" class="btn btn-default {$styles['button'][0]}" href="?ch=add" >添加</a> <a id="major" type="button" class="btn btn-default {$styles['button'][1]}" href="?ch=modi" >修改</a> </div>-->
  <div style="margin-top:50px; {$styles['box'][0]}">
    <form id="main" method="post" onSubmit="return check(this);"  enctype="multipart/form-data">
      <table class="table table-bordered col-md-12 main table-hover" >
        <tbody>
          <tr>
            <td rowspan="4" class="col-md-3">
              <img id="image" class="img-thumbnail img-responsive" style="display:none;max-height:250px ">
              <input type="file" id="img" name="img">
              <p id="tips" class="help-block">支持JPG,PNG,GIF,图片小于10MB。</p>
              <input name='url' value="" style="display:none">
              <button type="button" onClick="upfiles(this)" class="btn btn-primary" >上传</button>
            </td>
            <td class="col-md-1">飞机号</td>
            <td class="col-md-2"><select name="no" class="form-control" required>
                <volist name="fly" id="vo">
                  <option value="{$vo['no']}">{$vo['no']}</option>
                </volist>
              </select></td>
            <td class="col-md-1">出厂号码</td>
            <td class="col-md-2"><input type="text" name="man" class="form-control" disabled></td>
            <td class="col-md-1">专业</td>
            <td class="col-md-2"><select name="major" class="form-control" required>
                <volist name="majors" id="vo">
                  <option value="{$vo['id']}">{$vo['name']}</option>
                </volist>
              </select></td>
          </tr>
          <tr>
            <td>照相部位</td>
            <td><select name="place" class="form-control" required>
                <volist name="photos" id="vo">
                  <option value="{$vo['id']}">{$vo['name']}</option>
                </volist>
              </select></td>
            <td>工作时机</td>
            <td><select name="wtime" class="form-control" required>
                <volist name="wtime" id="vo">
                  <option value="{$vo['id']}">{$vo['name']}</option>
                </volist>
              </select></td>
            <td></td>
            <td></td>
          </tr>
          <tr>
            <td>工作人</td>
            <td><input type="text" name="poster" class="form-control" required></td>
            <td>复查人</td>
            <td><input type="text" name="checker" class="form-control" required></td>
            <td></td>
            <td></td>
          </tr>
          <tr>
            <td>工作日期</td>
            <td><input type="text" name="wdate" class="form-control" required></td>
            <td>照相日期</td>
            <td><input type="text" name="pdate" class="form-control" required></td>
            <td>照相人</td>
            <td><input type="text" name="photor" class="form-control" required></td>
          </tr>
        </tbody>
      </table>
      <button type="submit" class="btn btn-primary btn-lg col-md-offset-5">添加</button>
      <a  href="__ROOT__/Admin/view" class="btn btn-default btn-lg">返回</a>
    </form>
  </div>
  
  <volist name="Tdata" id="data">
    <div style="margin-top:50px; {$styles['box'][1]}">
      <form id="main" method="post"  onSubmit="return check(this);" action="__ROOT__/Admin/changePhoto"  enctype="multipart/form-data">
        <table class="table table-bordered col-md-12 main table-hover" >
          <tbody>
            <tr>
              <td rowspan="4" class="col-md-3"><img id="image" class="img-thumbnail img-responsive" src="{$data['url']}" style="max-height:250px">
                <input name="id" value="{$data['id']}" style="display:none">
                <input type="file" id="img" name="img">
                <p id="tips" class="help-block">支持JPG,PNG,GIF,图片小于10MB。</p>
                <input name='url' value="{$data['url']}" style="display:none">
                <button type="button" onClick="upfiles(this)" class="btn btn-primary" >上传</button>
              </td>
              <td class="col-md-1">飞机号</td>
              <td class="col-md-2"><input name="no" class="form-control" readonly value="{$data['plane']}" required></td>
              <td class="col-md-1">出厂号码</td>
              <td class="col-md-2"><input type="text" name="man" class="form-control" disabled></td>
              <td class="col-md-1">专业</td>
              <td class="col-md-2"><select name="major" class="form-control" required>
                  <volist name="majors" id="vo">
                  	<if condition="$data['major'] eq $vo['id'] "><option selected value="{$vo['id']}">{$vo['name']}</option>
                    <else /><option  value="{$vo['id']}">{$vo['name']}</option>
                    </if>
                  </volist>
                </select></td>
            </tr>
            <tr>
              <td>照相部位</td>
              <td><select name="place" class="form-control" required>
                  <volist name="photos" id="vo">
                  	<if condition="$data['place'] eq $vo['id'] "><option selected value="{$vo['id']}">{$vo['name']}</option>
                    <else /><option  value="{$vo['id']}">{$vo['name']}</option>
                    </if>
                    
                  </volist>
                  
                </select></td>
                


              <td>工作时机</td>
              <td><select name="wtime" class="form-control" required>
                  <volist name="wtime" id="vo">
                          <if condition="$data['wtime'] eq $vo['id'] "><option selected value="{$vo['id']}">{$vo['name']}</option>
                    <else /><option  value="{$vo['id']}">{$vo['name']}</option>
                    </if>   
       </volist>
                </select></td>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td>工作人</td>
              <td><input type="text" name="poster" class="form-control" value="{$data['poster']}" required></td>
              <td>复查人</td>
              <td><input type="text" name="checker" class="form-control" value="{$data['checker']}" required></td>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td>工作日期</td>
              <td><input type="text" name="wdate" class="form-control" value="{$data['wdate']}" required></td>
              <td>照相日期</td>
              <td><input type="text" name="pdate" class="form-control" value="{$data['pdate']}" required></td>
              <td>照相人</td>
              <td><input type="text" name="photor" class="form-control" value="{$data['photor']}" required></td>
            </tr>
          </tbody>
        </table>
        <button type="submit" class="btn btn-default btn-lg col-md-offset-5">保存</button>
        <button type="button" class="btn btn-danger btn-lg del">删除</button>
        <a type="button" href="__ROOT__/Admin/view" class="btn btn-primary btn-lg">返回</a>
      </form>
    </div>
  </volist>
</div>
<style>
.main{
	height:300px;	
	text-align:center; 
}

.main td{
	height:50px;	
}

</style>
<include file="./VMSTpl/Admin/tailer.html" /> 
<script>
$("document").ready(function(){
	txt = $("select[name='no']").val();
	$.post("__ROOT__/Admin/getMan",{no:txt},
		function (data){
		$("input[name='man']").val(data);
		})
		
	$("select[name='no']").change(function(){
		txt = $("select[name='no']").val();
		$.post("__ROOT__/Admin/getMan",{no:txt},
		function (data){
			$("input[name='man']").val(data);
		})
	})
	
	$(".del").click(function(){
		var id = $(this).parent("form").find("input[name='id']").val();
		var target = $(this).parent("form").parent();
		if(confirm("你确定要删除这条记录！")){
			var url = "__ROOT__/Admin/delPhoto?id="+id; 
				 
			$.get(url, function(data) { 
				if(data=="1") { 
					alert("删除失败！"); 
					return; 
				}
				else if(data=="0")
					alert("删除成功！"); 
				target.remove();
			}); 
		}
	})
	
	$("input[name='wdate']").cxCalendar({ 
			type:"yyyy-mm-dd",
	});
	
	$("input[name='pdate']").cxCalendar({ 
			type:"yyyy-mm-dd",
	});
})
function check(thisform){
	var wdate = $(thisform).find("input[name='wdate']").val();
	var pdate = $(thisform).find("input[name='pdate']").val();
	reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
	if(!reg.test(wdate)){
		alert("日期格式有误！");
		$(thisform).find("input[name='wdate']").focus();
		return false;
	}
	if(!reg.test(pdate)){
		alert("日期格式有误！");
		$(thisform).find("input[name='pdate']").focus();
		return false;
	}
	if($(thisform).find("#image").attr('src')=='' || $(thisform).find("#image").attr('src')==null){
		alert("请上传文件！");	
		return false;
	}
	return true
}
function upfiles(thisform) {
    var messtxt;
    $(thisform).parents("#main").ajaxSubmit({
        //dataType:'script',
        type: 'post',
        url: "__ROOT__/Admin/addImg",
        beforeSubmit: function() {
            $(thisform).prev("#tips").html("图片上传中...");
        },
        success: function(data) {
			if(data=="error")
				$(thisform).prevAll("#tips").html("请重新选择文件");
			else{
			    $(thisform).prevAll("#tips").html("上传成功");
				$(thisform).prevAll("#image").attr('src',"__PUBLIC__/Photos/tmp/"+data);
				$(thisform).prevAll("input[name='url']").val(data);
				$(thisform).prevAll("#image").show();
			}
            
        },
        resetForm: false,
        clearForm: false
    });
}


</script>